package com.aidex.biz.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.BusinessSet;
import com.aidex.biz.service.BusinessSetService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 业务设置Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2024-04-25
 */
@RestController
@RequestMapping("/biz/bizBusinessSet")
public class BusinessSetController extends BaseController
{
    @Autowired
    private BusinessSetService businessSetService;

    /**
     * 查询业务设置列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBusinessSet:list')")
    @GetMapping("/list")
    public R<PageInfo> list(BusinessSet businessSet, HttpServletRequest request, HttpServletResponse response)
    {
        if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                businessSet.setCompanyId(null);
        }else{
                     businessSet.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                 }
        businessSet.setPage(new PageDomain(request, response));
        return R.data(businessSetService.findPage(businessSet));
    }

    /**
     * 获取业务设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBusinessSet:query')")
    @GetMapping(value = "/{id}")
    public R<BusinessSet> detail(@PathVariable("id") String id)
    {
        return R.data(businessSetService.get(id));
    }

    /**
     * 新增业务设置
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBusinessSet:add')")
    @Log(title = "业务设置", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  BusinessSet businessSet)
    {
        return R.status(businessSetService.save(businessSet));
    }

    /**
     * 修改业务设置
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBusinessSet:edit')")
    @Log(title = "业务设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated BusinessSet businessSet)
    {
        return R.status(businessSetService.save(businessSet));
    }


    /**
     * 删除业务设置
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBusinessSet:remove')")
    @Log(title = "业务设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(businessSetService.deleteBusinessSetByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBusinessSet:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(businessSetService.findMaxSort(new BusinessSet()));
    }

    /**
     * 导出业务设置列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizBusinessSet:export')")
    @Log(title = "业务设置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(BusinessSet businessSet)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    businessSet.setCompanyId(null);
            }else{
                         businessSet.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<BusinessSet> list = businessSetService.findList(businessSet);
        ExcelUtil<BusinessSet> util = new ExcelUtil<BusinessSet>(BusinessSet.class);
        return util.exportExcel(list, "业务设置数据");
    }

}
